package com.lm.Composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 树枝节点
 */
public class Composite implements Component {

    private List<Component> children = new ArrayList<>();

    public void add(Component component){
        children.add(component);
    }

    public void remove(Component component){
        children.remove(component);
    }

    public Component getChild(Integer index){
        return children.get(index);
    }

    @Override
    public void operation() {
        for (Component child : children) {
            child.operation();
        }
    }
}
